<!--底部小播放器 -->
<template>
  <div class="mini-player-container" @click="enterFullscreenAction">
    <!-- 专辑图片 -->
    <div class="icon">
      <div class="img-wrapper">
        <img :class="{ pause: !playing }" :src="currentSong.al.picUrl" alt="" />
      </div>
    </div>
    <!-- 歌曲信息 -->
    <div class="text">
      <h2 class="name">{{ currentSong.name }}</h2>
      <p class="desc">{{ currentSong.ar }}</p>
    </div>
    <!-- 控制图标 -->
    <div class="contral" @click.stop="">
      <!-- <circle-progress v-model="playing" :progress="progress"></circle-progress> -->
      <!-- 如果v-model绑定的是仓库中的状态，那么久必能在使用v-model,如果使用了的话，
      就说明组件在修改仓库中的值，而仓库中的值只能被mutations修改 -->
      <circle-progress
        :value="playing"
        @input="changePlayingAction"
        :progress="progress"
      ></circle-progress>
    </div>
    <!-- 列表图标 -->
    <div class="contral" @click.stop="">
      <i class="iconfont icon-yinleliebiao"></i>
    </div>
  </div>
</template>

<script>
import CircleProgress from "./children/circle-progress";
import { mapState } from "vuex";
export default {
  components: {
    CircleProgress,
  },
  // 接收外部属性获取progress
  props: {
    progress: Number,
  },
  data() {
    return {
      // progress:0.3,
      // currentSong: {
      //   id: 1812673579,
      //   name: "等你归来",
      //   ar: "程响",
      //   al: {
      //     name: "等你归来",
      //     picUrl:
      //       "https://p1.music.126.net/bisOFZHy6WuBBfaHtr238Q==/109951165674729204.jpg",
      //   },
      // },
    };
  },
  computed: {
    // 把仓库的state转为组件的计算属性
    ...mapState({
      playing: (state) => state.Player.playing,
      currentSong: (state) => state.Player.currentSong
    }),
    // 获取仓库中当前播放的歌曲
    // ...mapGetters({
    //   currentSong: "Player/currentSong",
    // }),
  },
  methods: {
    changePlayingAction(value) {
      // console.log(this.progress)
      // console.log("改变",value)
      // 让仓库修改playing的值
      this.$store.commit({
        type: "Player/setPlaying",
        value,
      });
    },
    enterFullscreenAction() {
      console.log("enter");
      this.$store.commit({
        type: "Player/setFullScreen",
        value: true,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.mini-player-container {
  position: fixed;
  height: 60px;
  left: 0;
  bottom: 0;
  width: 100%;
  background: #fff;
  z-index: 1000;
  display: flex;
  align-items: center;
}
.icon {
  flex: 0 0 40px;
  height: 40px;
  width: 40px;
  margin: 0 10px 0 20px;
  .img-wrapper {
    width: 100%;
    height: 100%;
    img {
      border-radius: 50%;
      width: 100%;
      height: 100%;
      animation: roate 10s linear infinite;
      &.pause {
        animation-play-state: paused;
      }
    }
  }
}
.text {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 20px;
  overflow: hidden;
  .name {
    margin-bottom: 2px;
    font-size: 14px;
    color: #333;
  }
  .desc {
    font-size: 12px;
    color: #999;
  }
}
.contral {
  flex: 0 0 30px;
  padding: 0 10px;
  color: #d44439;
  .icon-yinleliebiao {
    font-size: 30px;
  }
}
</style>